from client import Client, DataBaseError

if __name__ == '__main__':
    '''
        备份数据
    '''
    org = 'houses'
    dst = 'houses_bak_0216'
    dst1 = 'houses_test_0216'
    client = Client()

    if not client.has_collection(org):
        raise DataBaseError("数据表不存在")
    org_table = client.get_collection(org)
    dst_table = client.get_collection(dst)
    dst_table1 = client.get_collection(dst1)

    dst_table.drop()
    dst_table1.drop()

    print("正在备份...")
    listt = [i for i in org_table.find({})]

    print("获取数据完成，正在写入...")
    dst_table.insert_many(listt)
    dst_table1.insert_many(listt)

    print("done!")
